package com.yznote.cloudesk.backstage.controller;

import com.yznote.cloudesk.common.constants.YCacheConstant;
import com.yznote.cloudesk.common.pojo.Result;
import com.yznote.cloudesk.common.utils.EhcacheUtils;
import com.yznote.cloudesk.logs.mapper.YLogsMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Api(tags = "日志管理")
@RestController
public class YLogsController {
    @Autowired
    YLogsMapper yLogsMapper;

    @ApiOperation("获得某接口某秒调用次数")
    @GetMapping("/getCountInSec")
    public Result getCountInSec(
            @RequestParam String moduleName,
            @RequestParam String methodName,
            @RequestParam
            @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") LocalDateTime requestTime) {
        return Result.success(yLogsMapper.getCountInSec(moduleName, methodName, requestTime));
    }

    @ApiOperation("获得某接口某段时间内调用次数")
    @GetMapping("/getCountBetweenSec")
    public Result getCountBetweenSec(@RequestParam String moduleName,
                                     @RequestParam String methodName,
                                     @RequestParam
                                     @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")LocalDateTime requestTimeStart,
                                     @RequestParam
                                     @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")LocalDateTime requestTimeEnd) {
        return Result.success(yLogsMapper.getCountBetweenSec(moduleName, methodName, requestTimeStart, requestTimeEnd));
    }

    @ApiOperation("获得某秒调用所有接口次数")
    @GetMapping("/getCountInSec111")
    public Result getCountInSec111(
            @RequestParam
            @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") LocalDateTime requestTime) {
        return Result.success(yLogsMapper.getCountInSec111(requestTime));
    }

}
